﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BT_web__nhom06.VanPhongDoan
{
    public partial class DSDoanVien : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {

                DataTable tbl = Tienichsql.ketnoicsdl.ChayLenhSelectDuLieu("SELECT masinhvien ,ho ,ten ,ngaysinh ,dienthoailienhe  FROM doanvien ");
                gvDoanVien.DataSource = tbl;
                gvDoanVien.DataBind();
            }

        }

        protected void btnApDungLoc_Click(object sender, EventArgs e)
        {
            string dieukienloc = " where ";

            //if (drlLocTheoChiDoan.Text != null)
            //    dieukienloc = dieukienloc + " machidoan='" + drlLocTheoChiDoan.Text + "'";

            if (string.IsNullOrEmpty(txtLocTheoTenDoanVien.Text)==false)
                dieukienloc = dieukienloc + " ten like N'%" + txtLocTheoTenDoanVien.Text + "%'";  //so sánh chuỗi unicode

            if (string.IsNullOrEmpty( txtLocTheoSoDienThoai.Text )==false)
                dieukienloc = dieukienloc + " DienThoaiLienHe like N'%" + txtLocTheoSoDienThoai.Text + "%'";

            if (dieukienloc == " where ") //chưa nhập giá trị lọc
                dieukienloc = "";


            string lenhSelectSQL = "SELECT masinhvien ,ho ,ten ,ngaysinh ,dienthoailienhe  FROM doanvien "+dieukienloc;
            //lenhSelectSQL+=dieukienloc;
            DataTable tbl2 = Tienichsql.ketnoicsdl.ChayLenhSelectDuLieu(lenhSelectSQL);

            gvDoanVien.DataSource = tbl2;
            gvDoanVien.DataBind();

            //gvDoanVien


        }

        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
           
        }

        protected void drlLocTheoChiDoan_SelectedIndexChanged(object sender, EventArgs e)
        {
            string lenhSelectSQL = "SELECT masinhvien ,ho ,ten ,ngaysinh ,dienthoailienhe  FROM doanvien where machidoan like N'%" + drlLocTheoChiDoan.Text + "%'";
            DataTable tbl2 = Tienichsql.ketnoicsdl.ChayLenhSelectDuLieu(lenhSelectSQL);
            gvDoanVien.DataSource = tbl2;
            gvDoanVien.DataBind();
        }
    }
}